const { Department } = require('../common/mysql.js')
const { Op } = require('sequelize')

module.exports = {
    async getDepartmentList() {
        const departmentList = await Department.findAll({})
        const topDepartment = departmentList.filter(item => item.parent_id === null)
        for (const index in topDepartment) {
            topDepartment[index].setDataValue(
                'children',
                departmentList.filter(item => item.parent_id === topDepartment[index].id)
            )
        }
        return topDepartment
    }
}
